_veh = (_this select 0);
_type = (typeOf _veh);
_hasTurrets = (count (configFile >> "CfgVehicles" >> _type >> "Turrets")) > 0;

{_veh removeMagazine _x;} forEach magazines _veh;

_magazines = if (_hasTurrets) then
{
    _ms = [];
    for "_i" from 0 to ((count (configFile >> "CfgVehicles" >> _type >> "Turrets")) - 1) do
    {
        _t = (configFile >> "CfgVehicles" >> _type >> "Turrets") select _i;
        _ms = _ms + (getArray (_t >> "magazines"));
    };
    _ms
}
else
{
    _ms = getArray (configFile >> "CfgVehicles" >> _type >> "magazines");
    _ms
};

{_veh addMagazine _x} forEach _magazines;